package com.ganwei.plugin.impl;

import com.ganwei.plugin.DataBase;
import com.ganwei.plugin.GanWeiPluginBean;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.concurrent.TimeUnit;

@GanWeiPluginBean
public class DB2DataBase implements DataBase {

    public final static Cache<Integer, String > cache = CacheBuilder.newBuilder()
            .maximumSize(500)
            .expireAfterWrite(10, TimeUnit.MINUTES)       //定时回收：没有写访问10分钟后失效清理
            .build();

    @Override
    public void getConnection() {
        System.out.println("this database is db2");
        cache.put(1,"dd");
        long size = cache.size();
        System.out.println("Guava cache size:"+size);
    }
}
